package com.sfh.pst.http;


import com.google.gson.Gson;
import com.sfh.base.LogUtil;
import com.sfh.base.http.server.ExceptionHandle;

import rx.Subscriber;

/**
 * 功能描述:请求返回
 * 1.处理特定返回码
 */

public  abstract class AppSyncSubscriber<T> extends Subscriber<T> {

    public abstract void onSuccee(T result) throws Exception;
    public abstract void onError(ExceptionHandle.ResponeThrowable e);
    @Override
    public void onStart() {

    }
    @Override
    public void onCompleted() {

    }


    @Override
    public void onError(Throwable e) {
        try{
            onError(ExceptionHandle.handleException (e));
        }catch (Exception e1){
            LogUtil.e (AppSyncSubscriber.class, "onError:" + e1);
        }

    }

    @Override
    public void onNext(T entity) {

        try {
            if (LogUtil.DEBUG){
                LogUtil.d ("http",new Gson ().toJson (entity));
            }

            onSuccee(entity);
        } catch (Exception e) {
            onError (e);
        }
    }


}
